<?   
    //класс для работы с формами
    class form
    {   
        var $action = '';   
        var $method = '';   
        var $form_start = '';   
        var $form_close = '</form>';   
        var $clform = '';   
        var $cols = '25';   
        var $rows = '4';   
        var $size = '';   
        var $maxlength;   
        var $text;   
        var $class="";

        function form ($action ='',$method= '')   
        {   
            $this->action = $action;   
            $this->method = $method;   
           // $this->form_start = '<form action="'.$action.'" method="'.$method.'">';   
        }   

        function textarea ($value, $name)
        { 
            $value = Htmlspecialchars($value);
            //_e ('<textarea name="'.$name.'" cols="26" rows="10">'.$value.'</textarea></td></tr>');
        }   

        //добавляем элемент
        function add($TYPE, $form_type=null, $NAME, $VALUE=null, $br=null, $option=null)   
        {   
            if ($form_type == '') {$form_type = 'text';}   
            //if ($br){$br = '<br />';}  
            $text = ''; 
            if (!empty($this->text)){$text = $this->text."\n";}   
            $size ='';
            if (!empty($this->size)){$size = 'size="'.$this->size.'"';}   
            if (!empty($this->maxlength)){$maxlength = 'maxlength="'.$this->maxlength.'"';}   
            $selected  = '';

            if ($TYPE == 'input')   
            {   
                $this->clform[] = $text.'<input class="'.$this->class.'" type="'.$form_type.'" name="'.$NAME.'" value="'.$VALUE.'" '.$size.' '.$maxlength.'/>'.$br;   
            }   
            elseif ($TYPE == 'textarea')   
            {   
                $this->clform[] = $text.'<textarea class="'.$this->class.'" name="'.$NAME.'" cols="'.$this->cols.'" rows="'.$this->rows.'" '.$maxlength.'>'.$VALUE.'</textarea>'.$br;   
            }   
            elseif ($TYPE == 'select')   
            {   
                $select  = $text.'<select class="'.$this->class.'" name="'.$NAME.'" '.$size.'>'."\n";   
                for ($i=0; $i<count($option); $i++)   
                {   
                    if ($option[$i][2] == 'selected'){$selected = 'selected="selected"';}   
                    $select .= '<option value="'.$option[$i][0].'" '.$selected.' '.$size.'>'.$option[$i][1].'</option>'."\n";   
                    $selected = '';   
                }   
                $select .= '</select>'.$br."\n";   
                $this->clform[] = $select;   
            }   
            elseif ($TYPE == 'checkbox')   
            {   
                if ($option == 'checked'){$checked = 'checked="checked"';}   
                $this->clform[] = $text.'<input class="'.$this->class.'" type="'.$form_type.'" name="'.$NAME.'" value="'.$VALUE.'" '.$checked.' '.$size.' '.$maxlength.'/>'.$br;   
            }   
            elseif ($TYPE == 'radio')   
            {   
                $this->clform[] = $text.'<input class="'.$this->class.'" type="'.$form_type.'" name="'.$NAME.'" value="'.$VALUE.'" '.$size.' '.$maxlength.'/>'.$br;   
            }   
            $this->text = '';   
            $this->size = '';   
            $this->maxlength = '';   
        }   

        //возвращает форму
        function get_form()   
        {   
            $form = $this->form_start."\n";   
            for ($i=0; $i<count($this->clform); $i++){$form .= $this->clform[$i]."\n";}   
           // $form .= $this->form_close."\n";   
            return $form;   
        }   
    }   
?>